package net.zdreamer.geracomium.application;

import android.app.Application;

import com.android.volley.RequestQueue;
import com.android.volley.toolbox.Volley;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import com.nostra13.universalimageloader.core.assist.QueueProcessingType;

import net.zdreamer.geracomium.protocol.MoccaApi;
import net.zdreamer.geracomium.protocol.MoccaApiImpl;

public class BaseApplication extends Application {
    private MoccaApi mMoccaApi;
    private static BaseApplication mApplication;
    private RequestQueue requestQueue;
    private String token;
    private String userId;

    @Override
    public void onCreate() {
        super.onCreate();
        mMoccaApi = new MoccaApiImpl();
        mApplication = this;
        initImageLoader();
        requestQueue = Volley.newRequestQueue(mApplication);
    }

    public RequestQueue getRequestQueue() {
        return requestQueue;
    }

    public static BaseApplication get() {
        return mApplication;
    }

    public MoccaApi getMoccaApi() {
        return mMoccaApi;
    }

    private void initImageLoader() {
        DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder().cacheInMemory(true) // 1.8.6包使用时候，括号里面传入参数true
                .imageScaleType(ImageScaleType.NONE).cacheOnDisk(true) // 1.8.6包使用时候，括号里面传入参数true
                .build();
        ImageLoaderConfiguration config =
                new ImageLoaderConfiguration.Builder(mApplication).threadPriority(Thread.NORM_PRIORITY - 2)
                        .defaultDisplayImageOptions(defaultOptions)
                        .denyCacheImageMultipleSizesInMemory()
                        .tasksProcessingOrder(QueueProcessingType.LIFO) // Not
                                // necessary
                                // in common
                        .build();
        ImageLoader.getInstance().init(config);
    }

    public String getToken() {
        return token;
    }

    public void setToken(String token) {
        this.token = token;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }


}
